package org.example;

public class 第二十一章_继承 {
    public static void main(String[] args) {
        animal p1 = new penguin("企鹅",5);
        animal p2 = new rat("老鼠",1);

        p1.introduction();
        p1.eat();
        p1.sleep();

        p2.introduction();
        p2.eat();
        p2.sleep();
    }

    static class animal{
        String name;
        int age;

        public animal(String name,int age){
            this.name = name;
            this.age = age;
        }

        public void eat(){
            System.out.println(name+"正在吃");
        }
        public void sleep(){
            System.out.println(name+"正在睡");
        }
        public void introduction() {
            System.out.println("大家好！我是"+ name + ".");
        }
    }

    static class penguin extends animal{
        public penguin(String name,int age){
            super(name,age);
        }
    }

    static class rat extends animal{
        public rat(String name,int age){
            super(name,age);
        }
    }
}
